package utils

import (
	"math/rand"
	"strconv"
	"time"
)

func RandString(len int) string {
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	bytes := make([]byte, len)
	for i := 0; i < len; i++ {
		b := r.Intn(26) + 65
		bytes[i] = byte(b)
	}
	return string(bytes)
}

func convertIntSlice2Map(slice []interface{}) map[interface{}]struct{} {
	set := make(map[interface{}]struct{}, len(slice))
	for _, v := range slice {
		set[v] = struct{}{}
	}
	return set
}

// 仿php in_array函数
func In_array(element interface{}, slice []interface{}) bool {
	m := convertIntSlice2Map(slice)
	_, ok := m[element]
	return ok
}

//int数据转为string
func Int2string(num uint) string {
	//var str string
	str := strconv.FormatInt(int64(num), 10)
	return str
}
